<?php
/**
 * Template designed by 12leaves.com
 * 12leaves.com - Free ecommerce templates and design services
 *
 * Side Box Template
 *
 * @package templateSystem
 * @copyright Copyright 2003-2006 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: tpl_categories.php 4162 2006-08-17 03:55:02Z ajeh $
 */

/*
 可以显示出所有的分类
 
<div class="side_menu">
 <div class="cat_menu selected">
     <a class="level_0" href="#">男士西装</a>
     <ul class="level_1">
     <li><a href="#" class="current">西装套装</a></li>
     <li><a href="#">西装上衣</a></li>
     <li><a href="#">正装裤子</a></li>
     </ul>
 </div>
 <div class="cat_menu">
     <a class="level_0" href="#">男士西装</a>
     <ul class="level_1">
     <li><a href="#">西装套装</a></li>
     <li><a href="#">西装上衣</a></li>
     <li><a href="#">正装裤子</a></li>
     </ul>
 </div>
 <div class="cat_menu">
     <a class="level_0" href="#">男士西装</a>
     <ul class="level_1">
     <li><a href="#">西装套装</a></li>
     <li><a href="#">西装上衣</a></li>
     <li><a href="#">正装裤子</a></li>
     </ul>
 </div>
</div>

 */

$content = "";

$content .= //'<div class="side_menu">' . "\n".
        "\n";    //默认选中

//print_r($box_categories_array);
/*if(zen_not_null($current_category_id)) {
 $result=mysql_query("SELECT cd.categories_name,c.categories_id FROM categories c left join categories_description cd on c.categories_id = cd.categories_id where c.parent_id = 0 and c.categories_status=1 and c.categories_id = '" . $current_category_id . "' and (not cd.categories_name='') order by c.sort_order");
 } else {
 $result=mysql_query("SELECT cd.categories_name,c.categories_id FROM categories c left join categories_description cd on c.categories_id = cd.categories_id where c.parent_id = 0 and c.categories_status=1 and (not cd.categories_name='') order by c.sort_order");
 }*/

global $db ;

$catagroies = array();

//level_0
$result=$db->Execute("SELECT cd.categories_name,c.categories_id FROM categories c left join categories_description cd on c.categories_id = cd.categories_id where c.parent_id = 0 and c.categories_status=1 and (not cd.categories_name='') order by c.sort_order");
while(!$result->EOF){

    $catagroies[$result->fields['categories_id']] = array('name'=>$result->fields['categories_name'],
        'level'=>0,
        'parent'=>$result->fields['parent_id'],
        'next_id'=>false,
    );
    if (isset($parent_id)) {
        $catagroies[$parent_id]['next_id'] = $result->fields['categories_id'];
    }

    $parent_id = $result->fields['categories_id'];

    if (!isset($first_element)) {
        $first_element = $result->fields['categories_id'];
    }
    
    $select_css = "";
    $nowPath = explode("_", $cPath);
    if( $nowPath[0] == $result->fields['categories_id']){
        $select_css = "selected";
    }
    $content .= ' <div class="cat_menu '.$select_css.'">'."\n";
    $content .= '<a class="level_0" href="'.zen_href_link(FILENAME_DEFAULT, 'cPath='.$result->fields['categories_id']).'" >'.$result->fields['categories_name'].'</a>';

    //level_1
    $result1=$db->Execute("SELECT cd.categories_name,c.categories_id FROM categories c left join categories_description cd on c.categories_id = cd.categories_id where c.parent_id = ".$result->fields['categories_id']." and c.categories_status=1 and (not cd.categories_name='') order by c.sort_order");

    if($result1->RecordCount() > 0){
        $content.=' <ul  class="level_1">';
        while(!$result1->EOF){
            //$tmp=zen_href_link(FILENAME_DEFAULT, 'cPath='.$result1->fields['categories_id']);
            //$tmpa=explode("?", $tmp);

            //$level_1 = $catagroies[$result->fields['categories_id']];
            //$catagroies[$level_0][$level_1] = array();
            //$catagroies[$level_0][$level_1]["name"]=$result1->fields['categories_name'];

            $catagroies[$result1->fields['categories_id']] = array('name'=>$result1->fields['categories_name'],
                'level'=>1,
                'parent'=>$parent_id,
                'next_id'=>false,
            );
            if (isset($parent_id1)) {
                $catagroies[$parent_id1]['next_id'] = $result1->fields['categories_id'];
            }

            $parent_id1 = $result1->fields['categories_id'];

            if (!isset($first_element1)) {
                $first_element1 = $result1->fields['categories_id'];
            }

            
            $content.=' <li ><a href="'.zen_href_link(FILENAME_DEFAULT, 'cPath='.$result->fields['categories_id'].'_'.$result1->fields['categories_id']).'">'.$result1->fields['categories_name'].'</a>';

            //level_2
            $result2=$db->Execute("SELECT cd.categories_name,c.categories_id FROM categories c left join categories_description cd on c.categories_id = cd.categories_id where c.parent_id = ".$result1->fields['categories_id']." and c.categories_status=1 and (not cd.categories_name='') order by c.sort_order");

            if($result2->RecordCount() > 0){
                $content.='<ul>';
                while(!$result2->EOF){
                    //$tmp=zen_href_link(FILENAME_DEFAULT, 'cPath='.$result2->fields['categories_id']);
                    // $tmpa=explode("?", $tmp);

                    $catagroies[$result2->fields['categories_id']] = array('name'=>$result2->fields['categories_name'],
                        'level'=>2,
                        'parent'=>$parent_id1,
                        'next_id'=>false,
                    );
                    if (isset($parent_id2)) {
                        $catagroies[$parent_id2]['next_id'] = $result2->fields['categories_id'];
                    }

                    $parent_id2 = $result2->fields['categories_id'];

                    if (!isset($first_element2)) {
                        $first_element2 = $result2->fields['categories_id'];
                    }

                    $content.=' <li><a href="'.zen_href_link(FILENAME_DEFAULT, 'cPath='.$result->fields['categories_id'].'_'.$result1->fields['categories_id'].'_'.$result2->fields['categories_id']).'">'.$result2->fields['categories_name'].'</a></li>';
                    $result2->MoveNext();
                }//end while
                $content.='</ul>';
            }// end if
            $content.='</li>';
            $result1->MoveNext();
        } // end while


        $content.='</ul>';
        
        $content .='</div>';    //end cat_menu
    }// end if

    
    $content.='</li>';
    $result->MoveNext();
}
$content.='</div>'."\n";

//print_r($catagroies);

if (1==0 && SHOW_CATEGORIES_BOX_SPECIALS == 'true' or SHOW_CATEGORIES_BOX_PRODUCTS_NEW == 'true' or SHOW_CATEGORIES_BOX_FEATURED_PRODUCTS == 'true' or SHOW_CATEGORIES_BOX_PRODUCTS_ALL == 'true') {
    //------ display a separator between categories and links
    if (SHOW_CATEGORIES_SEPARATOR_LINK == '1') {
        //$content .= '<br>' ;
    }
    if (SHOW_CATEGORIES_BOX_SPECIALS == 'true') {
        $show_this = $db->Execute("select s.products_id from " . TABLE_SPECIALS . " s where s.status= 1 limit 1");
        if ($show_this->RecordCount() > 0) {
            // $content .= '<a class="category-links" href="' . zen_href_link(FILENAME_SPECIALS,'',"",false) . '">' . CATEGORIES_BOX_HEADING_SPECIALS . '</a>' . '<br />' . "\n";
        }
    }
    if (SHOW_CATEGORIES_BOX_PRODUCTS_NEW == 'true') {
        // ---- display limits
        //------- $display_limit = zen_get_products_new_timelimit();
        $display_limit = zen_get_new_date_range();

        $show_this = $db->Execute("select p.products_id
from " . TABLE_PRODUCTS . " p
where p.products_status = 1 " . $display_limit . " limit 1");
        if ($show_this->RecordCount() > 0) {
            // $content .= '<a class="category-links" href="' . zen_href_link(FILENAME_PRODUCTS_NEW,'',"",false) . '">' . CATEGORIES_BOX_HEADING_WHATS_NEW . '</a>' . '<br />' . "\n";
        }
    }
    if (SHOW_CATEGORIES_BOX_FEATURED_PRODUCTS == 'true') {
        $show_this = $db->Execute("select products_id from " . TABLE_FEATURED . " where status= 1 limit 1");
        if ($show_this->RecordCount() > 0) {
            // $content .= '<a class="category-links" href="' . zen_href_link(FILENAME_FEATURED_PRODUCTS,'',"",false) . '">' . CATEGORIES_BOX_HEADING_FEATURED_PRODUCTS . '</a>' . '<br />' . "\n";
        }
    }
    if (SHOW_CATEGORIES_BOX_PRODUCTS_ALL == 'true') {
        // $content .= '<a class="category-links" href="' . zen_href_link(FILENAME_PRODUCTS_ALL,"","",false) . '">' . CATEGORIES_BOX_HEADING_PRODUCTS_ALL . '</a>' . "\n";
    }

}

$content .= $priceListOutString;

/*
$content .='<div class="side_ads">
                	<div class="banner">
                    	<a href="#"><img src="images/cat/banner_sidebar_a.jpg" /></a>
                    </div>
                	<div class="banner">
                    	<a href="#"><img src="images/cat/banner_sidebar_b.jpg" /></a>
                    </div>
                </div>';
*/
//$content .= '</div>';
?>